<template>
  <div>
    <ContentWrap>
      <el-form ref="formRef" :model="formData" :rules="rules" label-width="250">
        <sub-title title="系统安全配置" />
        <el-form-item label="操作日志保存期限（天）" prop="logExpiresDay">
          <ns-input
            v-model="formData.logExpiresDay"
            @input="(value) => handleInput(value, 'logExpiresDay')"
            placeholder="请输入"
            maxlength="6"
          />
          长度不能超过6位，必须大于0
        </el-form-item>
        <el-form-item label="最大登录错误次数" prop="maxErrorSize">
          <ns-input
            v-model="formData.maxErrorSize"
            @input="(value) => handleInput(value, 'maxErrorSize')"
            placeholder="请输入"
            maxlength="2"
          />
          长度不能超过2位，必须大于0
        </el-form-item>
        <el-form-item label="登录失败，账户锁定时间（分钟）" prop="lockTime">
          <ns-input
            v-model="formData.lockTime"
            @input="(value) => handleInput(value, 'lockTime')"
            placeholder="请输入"
            maxlength="5"
          />
          长度不能超过5位，0表示永不锁定
        </el-form-item>
        <el-form-item label="会话保持时间（秒）" prop="accessTokenValiditySeconds">
          <ns-input
            v-model="formData.accessTokenValiditySeconds"
            @input="(value) => handleInput(value, 'accessTokenValiditySeconds')"
            maxlength="5"
            placeholder="请输入"
          />
          长度不能超过5位，0表示不限制
        </el-form-item>
        <sub-title title="密码策略配置" />
        <el-form-item label="密码最小长度" prop="minLength">
          <ns-input
            v-model="formData.minLength"
            @input="(value) => handleInput(value, 'minLength')"
            maxlength="2"
            placeholder="请输入"
          />
          不能超过2位，0表示不限制
        </el-form-item>
        <el-form-item label="密码复杂度" prop="passwordComplexity">
          <el-checkbox-group
            v-model="formData.passwordComplexity"
            class="w-100%"
            @change="passwordComChange"
          >
            <el-checkbox label="1">数字（0-9）</el-checkbox>
            <el-checkbox label="2">字母（a-zA-Z）</el-checkbox>
            <el-checkbox label="3">特殊字符（!@#$%^&*）</el-checkbox>
          </el-checkbox-group>
          新设置密码中必须包含所勾选内容，若不勾选则不限制
        </el-form-item>
        <el-form-item label="默认密码" prop="defaultPassword">
          <ns-input v-model="formData.defaultPassword" placeholder="请输入" show-password />
          新增用户将默认填写该密码
        </el-form-item>
        <sub-title title="文件样本设置" />
        <el-form-item label="最大上传文件（M）" prop="maxFileSize">
          <el-input
            v-model="formData.maxFileSize"
            @input="(value) => handleInput(value, 'maxFileSize')"
            placeholder="请输入"
            maxlength="5"
          />
          长度不能超过5位，0表示不限制
        </el-form-item>
        <el-form-item label="是否保存样本文件" prop="isSaveSample">
          <el-radio-group v-model="formData.isSaveSample" min="0">
            <el-radio :label="true" :value="true">保存样本文件</el-radio>
            <el-radio :label="false" :value="false">不保存样本文件</el-radio>
          </el-radio-group>
        </el-form-item>
        <sub-title title="审核有效性" />
        <el-form-item label="是否开启资产录入审核" prop="isOpenAssetAudit" class="w-100%">
          <el-radio-group
            v-model="formData.isOpenAssetAudit"
            class="w-100%"
            @change="isOpenAssetAuditChange"
          >
            <el-radio :label="true" :value="true">开启</el-radio>
            <el-radio :label="false" :value="false">关闭</el-radio>
          </el-radio-group>
          <div> 关闭审核后，待确认自查提交的资产自动视为审核通过 </div>
        </el-form-item>
        <el-form-item
          label="是否开启资产敏感级别自动变更审核"
          prop="isOpenAssetAuditSensitive"
          class="w-100%"
        >
          <el-radio-group
            v-model="formData.isOpenAssetAuditSensitive"
            class="w-100%"
            @change="isOpenAssetAuditSensitiveChange"
          >
            <el-radio :label="true" :value="true">开启</el-radio>
            <el-radio :label="false" :value="false">关闭</el-radio>
          </el-radio-group>
          <div> 关闭审核后，资产敏感级别自动变更视为审核通过 </div>
        </el-form-item>
        <el-form-item label="审核有效性（天）" prop="auditExpiresDay">
          <ns-input
            v-model="formData.auditExpiresDay"
            @input="(value) => handleInput(value, 'auditExpiresDay')"
            placeholder="请输入"
          />
          若审核节点未在期限内审核，则自动审核为不通过
        </el-form-item>
        <sub-title title="消息提醒设置" />
        <el-form-item label="变更审核提醒：" prop="isOpenDeadLineWarn" class="w-100%">
          <el-radio-group v-model="formData.isOpenDeadLineWarn" class="w-100%">
            <el-radio :label="true" :value="true">是</el-radio>
            <el-radio :label="false" :value="false">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="敏感期限范围1：">
          小于等于
          <el-input-number v-model="formData.scopeNumOne" :min="0" class="ml-12px" />
          <el-select v-model="formData.unit" class="ml-12px !w-100px">
            <el-option
              v-for="(item, index) in timeUnit"
              :key="index"
              :label="item.label"
              :value="item.label"
            />
          </el-select>
          <el-button type="text" class="ml-12px" @click="SetConfig('One')">配置</el-button>
        </el-form-item>
        <el-form-item label="敏感期限范围2：">
          大于
          <el-input-number v-model="formData.scopeNumOne" :min="0" class="ml-12px" />
          <el-select v-model="formData.unit" class="ml-12px mr-12px !w-100px">
            <el-option
              v-for="(item, index) in timeUnit"
              :key="index"
              :label="item.label"
              :value="item.label"
            />
          </el-select>
          小于
          <el-input-number v-model="formData.scopeNumTwo" :min="0" class="ml-12px" />
          <el-select v-model="formData.unit" class="ml-12px !w-100px">
            <el-option
              v-for="(item, index) in timeUnit"
              :key="index"
              :label="item.label"
              :value="item.label"
            />
          </el-select>
          <el-button type="text" class="ml-12px" @click="SetConfig('Two')">配置</el-button>
        </el-form-item>
        <el-form-item label="敏感期限范围3：">
          大于等于
          <el-input-number v-model="formData.scopeNumTwo" :min="0" class="ml-12px" />
          <el-select v-model="formData.unit" class="ml-12px !w-100px">
            <el-option
              v-for="(item, index) in timeUnit"
              :key="index"
              :label="item.label"
              :value="item.label"
            />
          </el-select>
          <el-button type="text" class="ml-12px" @click="SetConfig('Three')">配置</el-button>
        </el-form-item>
        <sub-title title="文件下载隐藏信息配置" />
        <el-form-item label="信息配置：" prop="fileHiddenConfig">
          <el-select v-model="formData.fileHiddenConfig" multiple>
            <el-option
              v-for="(item, index) in fieldList"
              :key="index"
              :label="item.label"
              :value="item.label"
            />
          </el-select>
        </el-form-item>
        <sub-title title="智能分类模式设置" />
        <el-form-item label="是否分类分级">
          <el-radio-group v-model="saveValue.marked">
            <el-radio label="1">是</el-radio>
            <el-radio label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <div v-if="saveValue.marked === '1'">
          <el-form-item label="信息配置：" prop="isDataMark">
            <el-row :gutter="24" style="width: 100%">
              <el-col :span="3" class="mb6">
                <el-checkbox
                  style="display: inline"
                  label="rule"
                  true-label="1"
                  false-label="0"
                  class="pr5"
                  key="rule"
                  v-model="saveValue.ruleMark"
                  >规则打标</el-checkbox
                >
              </el-col>
              <el-col :span="7">
                <el-form-item
                  v-if="saveValue.ruleMark == '1'"
                  label="优先级"
                  label-width="110px"
                  :prop="saveValue.ruleMark == '1' ? 'rulePriority' : ''"
                >
                  <ns-input
                    style="display: inline; width: 200px"
                    placeholder="请输入优先级"
                    v-model="saveValue.rulePriority"
                    clearable
                    type="number"
                  />
                </el-form-item>
              </el-col>
              <!-- <el-col :span="14">
                  <el-form-item
                    label="数据标准"
                    prop="markedTemplateId"
                    label-width="140px"
                    v-if="saveValue.ruleMark == '1'"
                  >
                    <el-select v-model="saveValue.markedTemplateId" clearable>
                      <el-option
                        v-for="item in markedTemplateInfo"
                        :label="item.dataStandardName"
                        :value="item.id"
                        :key="item.id"
                      />
                    </el-select>
                  </el-form-item>
                </el-col> -->
            </el-row>
            <el-row :gutter="24" style="width: 100%">
              <el-col :span="3" class="mb6">
                <el-checkbox
                  style="display: inline"
                  label="module"
                  class="pr5"
                  key="module"
                  true-label="1"
                  false-label="0"
                  v-model="saveValue.moduleMark"
                  >机器学习模型</el-checkbox
                >
              </el-col>
              <el-col :span="7">
                <el-form-item
                  v-if="saveValue.moduleMark == '1'"
                  label="优先级"
                  label-width="110px"
                  :prop="saveValue.moduleMark == '1' ? 'modulePriority' : ''"
                >
                  <ns-input
                    style="display: block; width: 100%"
                    placeholder="请输入优先级"
                    v-model="saveValue.modulePriority"
                    type="number"
                    clearable
                  />
                </el-form-item>
              </el-col>
              <!-- <el-col :span="10">
                  <el-form-item
                    label="机器学习模型"
                    :prop="saveValue.moduleMark == '1' ? 'moduleId' : ''"
                    label-width="140px"
                    v-if="saveValue.moduleMark == '1'"
                  >
                    <el-select
                      style="display: inline-block; width: 200px"
                      placeholder="请选择机器学习模型"
                      v-model="saveValue.moduleId"
                      clearable
                    >
                      <el-option label="个人信息安全模型" value="1" />
                    </el-select>
                  </el-form-item>
                </el-col> -->
            </el-row>
            <el-row :gutter="24" style="width: 100%">
              <el-col :span="3">
                <el-checkbox
                  style="display: inline"
                  label="file"
                  key="file"
                  class="pr5"
                  true-label="1"
                  false-label="0"
                  v-model="saveValue.fileMark"
                  >文件相似度</el-checkbox
                >
              </el-col>
              <el-col :span="7">
                <el-form-item
                  v-if="saveValue.fileMark == '1'"
                  label="优先级"
                  label-width="110px"
                  :prop="saveValue.fileMark == '1' ? 'filePriority' : ''"
                >
                  <ns-input
                    style="display: inline; width: 200px"
                    placeholder="请输入优先级"
                    v-model="saveValue.filePriority"
                    type="number"
                    clearable
                  />
                </el-form-item>
              </el-col>
              <el-col :span="14">
                <el-form-item
                  label="相似度指纹算法"
                  prop="likeSignAlgo"
                  label-width="140px"
                  v-if="saveValue.fileMark == '1'"
                >
                  <el-checkbox-group
                    v-model="saveValue.likeSignAlgo"
                    style="display: inline"
                    @change="console.log('change', saveValue.likeSignAlgo)"
                  >
                    <el-checkbox label="MD5">
                      <span>MD5</span>
                    </el-checkbox>
                    <el-checkbox label="KFS">
                      <span>KFS</span>
                    </el-checkbox>
                    <el-checkbox label="PFS">
                      <span style="margin-right: 9px">PFS</span>
                    </el-checkbox>
                    <el-checkbox label="PSA">
                      <span>PSA</span>
                    </el-checkbox>
                  </el-checkbox-group>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24" style="width: 100%" class="mt-23px">
              <el-col :span="3" />
              <el-col :span="21">
                <el-form-item
                  label="相似度阈值"
                  label-width="110px"
                  prop="likeThreshold"
                  v-if="saveValue.fileMark == '1'"
                >
                  <ns-input
                    style="display: inline; width: 123px"
                    v-model="saveValue.likeThreshold"
                    class="mr2"
                    clearable
                    @input="
                      saveValue.likeThreshold = saveValue.likeThreshold.replace(
                        /^0+(\d)|[^\d]+/g,
                        ''
                      )
                    "
                  />
                  百分比
                </el-form-item>
              </el-col>
            </el-row>
          </el-form-item>
        </div>
        <sub-title title="登录失败提示信息设置" />
        <el-form-item label="提示内容：" prop="loginTips">
          <ns-input type="textarea" v-model="formData.loginTips" />
        </el-form-item>
        <!-- <sub-title title="语言设置" />
        <el-form-item label="语言设置：" prop="language">
          <el-radio-group v-model="formData.language">
            <el-radio label="中文" value="中文">中文</el-radio>
            <el-radio label="英文" value="英文">英文</el-radio>
          </el-radio-group>
        </el-form-item> -->
      </el-form>
      <el-button @click="submit" v-hasPermi="['system:config:edit']">提交</el-button>
    </ContentWrap>
  </div>
</template>
<script lang="ts" setup>
import { ElMessage } from 'element-plus'
import SubTitle from '@/components/SubTitle/index.vue'
import * as ConfigApi from '@/api/system/config'
import { set, cloneDeep } from 'lodash-es'
import { ComponentInternalInstance, getCurrentInstance } from 'vue'
const message = useMessage() // 消息弹窗
const { proxy } = getCurrentInstance() as ComponentInternalInstance
const formRef = ref()
const formData = ref({
  logExpiresDay: undefined,
  maxErrorSize: undefined,
  lockTime: undefined,
  accessTokenValiditySeconds: undefined,
  refreshTokenValiditySeconds: undefined,
  minLength: undefined,
  passwordComplexity: undefined,
  defaultPassword: undefined,
  maxFileSize: undefined,
  isSaveSample: undefined,
  isOpenAssetAudit: undefined,
  isOpenAssetAuditSensitive: undefined,
  auditExpiresDay: undefined,
  scopeNumOne: undefined,
  scopeNumTwo: undefined,
  unit: undefined,
  isOpenDeadLineWarn: undefined,
  fileHiddenConfig: undefined,
  classificationPattern: undefined,
  loginTips: undefined,
  language: undefined
})

// 默认密码校验
const validatePassword = (rule: any, value: any, callback: any) => {
  const complexities = formData.value.passwordComplexity.map(Number)
  const passwordRule = {
    includeDigits: complexities.indexOf(1) !== -1,
    includeLetters: complexities.indexOf(2) !== -1,
    includeSpecialChars: complexities.indexOf(3) !== -1,
    length: formData.value.minLength
  }

  // 构建正则表达式，根据校验规则生成对应的正则模式
  let pattern = '^'
  if (passwordRule.includeDigits) pattern += '(?=.*[0-9])' // 包含数字
  if (passwordRule.includeLetters) pattern += '(?=.*[a-zA-Z])' // 包含字母
  if (passwordRule.includeSpecialChars) pattern += '(?=.*[!@#$%^&+=])' // 包含特殊字符，你也可以根据具体需要调整特殊字符的范围
  pattern += `.{${passwordRule.length},}$` // 最小长度

  // 创建正则表达式对象
  const regex = new RegExp(pattern)

  // 进行校验
  if (!regex.test(value)) {
    callback(new Error('密码校验失败'))
  } else {
    callback()
  }
}
const SIGNPRIORITY = {
  MD5: 1,
  KFS: 2,
  PFS: 3,
  PSA: 4
}
const validateSignPriority = () => {
  let isNull = false
  const SIGNARR = []
  for (let i in SIGNPRIORITY) {
    if (saveValue.value.likeSignAlgo.includes(i)) {
      !saveValue.value[`priority${SIGNPRIORITY[i]}`]
        ? (isNull = true)
        : SIGNARR.push(saveValue.value[`priority${SIGNPRIORITY[i]}`])
    } else {
      if (saveValue.value[`priority${SIGNPRIORITY[i]}`]) {
        ElMessage.error('未选择的相似度指纹算法不能填写优先级！')
        return true
      }
    }
  }
  if (isNull) {
    ElMessage.error('选择相似度指纹算法后必须填写优先级！')
    return isNull
  }
  const setSign = new Set(SIGNARR)
  if (setSign.size < SIGNARR.length) {
    ElMessage.error('相似度指纹算法优先级不能相同！')
    return true
  }
}

const priorityInput = (index) => {
  saveValue.value[index] = saveValue.value[index].replace(/^0+(\d)|[^\d]+/g, '')
}
// 使用正则表达式只允许输入0-9的数字
function handleInput(value, key) {
  const filteredValue = value.replace(/[^0-9]/g, '')

  if (filteredValue !== formData.value[key]) {
    formData.value[key] = filteredValue
  }
}

//优先级校验规则
const validateFile = (rule: any, value: any, callback: any) => {
  if (
    saveValue.value.moduleMark == '1' &&
    saveValue.value.modulePriority == saveValue.value.filePriority &&
    saveValue.value.filePriority != ''
  ) {
    callback(new Error('优先级不能相同'))
  } else if (
    saveValue.value.ruleMark == '1' &&
    saveValue.value.rulePriority == saveValue.value.filePriority &&
    saveValue.value.filePriority != ''
  ) {
    callback(new Error('优先级不能相同'))
  } else if (saveValue.value.fileMark && saveValue.value.filePriority == '') {
    callback(new Error('请输入优先级'))
  } else {
    callback()
  }
}

const validateRule = (rule: any, value: any, callback: any) => {
  if (
    saveValue.value.fileMark == '1' &&
    saveValue.value.filePriority == saveValue.value.rulePriority &&
    saveValue.value.rulePriority != ''
  ) {
    callback(new Error('优先级不能相同'))
  } else if (
    saveValue.value.moduleMark == '1' &&
    saveValue.value.modulePriority == saveValue.value.rulePriority &&
    saveValue.value.rulePriority != ''
  ) {
    callback(new Error('优先级不能相同'))
  } else if (saveValue.value.ruleMark && saveValue.value.rulePriority == '') {
    callback(new Error('请输入优先级'))
  } else {
    callback()
  }
}
const validatemodule = (rule: any, value: any, callback: any) => {
  if (
    saveValue.value.fileMark == '1' &&
    saveValue.value.filePriority == saveValue.value.modulePriority &&
    saveValue.value.modulePriority != ''
  ) {
    callback(new Error('优先级不能相同'))
  } else if (
    saveValue.value.ruleMark == '1' &&
    saveValue.value.rulePriority == saveValue.value.modulePriority &&
    saveValue.value.modulePriority != ''
  ) {
    callback(new Error('优先级不能相同'))
  } else if (saveValue.value.moduleMark && saveValue.value.modulePriority == '') {
    callback(new Error('请输入优先级'))
  } else {
    callback()
  }
}
const validatePass = (rule: any, value: any, callback: any) => {
  if (
    (saveValue.value.moduleMark === '0' || saveValue.value.moduleMark === null) &&
    (saveValue.value.fileMark === '0' || saveValue.value.fileMark === null) &&
    (saveValue.value.ruleMark === '0' || saveValue.value.ruleMark === null)
  ) {
    callback(new Error('请选择数据打标方式'))
  } else {
    callback()
  }
}

const validateMaxErrorSize = (rule: any, value: any, callback: any) => {
  if (value < 1) {
    callback(new Error('最大登陆错误次数必须大于0'))
  } else {
    callback()
  }
}

const validatelogExpiresDay = (rule: any, value: any, callback: any) => {
  if (value < 1) {
    callback(new Error('操作日志保存期限必须大于0'))
  } else {
    callback()
  }
}

const saveValueCopy = {
  isDataMark: '',
  scanCycleTime: 0,
  scanCycleNum: 1,
  markedTemplateId: '',
  scanCycle: 'month',
  templateName: '',
  scanCycleMethod: 1,
  templateDesc: '',
  templateType: '0',
  status: 0,
  marked: '1',
  scanCycleType: 1,
  dbScanType: 0,
  scanSamples: 1,
  scanSamplesLine: 10,
  scanSamplesType: 0,
  fileScanType: 0,
  fileSize: 0,
  likeThreshold: 0,
  likeSignAlgo: [],
  priority: '',
  moduleId: '',
  filePriority: '',
  modulePriority: '',
  rulePriority: '',
  fileScanClass: [],
  ruleMark: '0',
  moduleMark: '0',
  fileMark: '0',
  fileType: 1,
  priority1: '1',
  priority2: '2',
  priority3: '3',
  priority4: '4'
}
const saveValue = ref(saveValueCopy)

const rules = {
  logExpiresDay: [
    { required: true, message: '操作日志保存期限（天）不能为空', trigger: 'blur' },
    { min: 1, max: 6, message: '', trigger: 'blur' },
    { validator: validatelogExpiresDay, required: true, trigger: 'blur' }
  ],
  maxErrorSize: [
    { required: true, message: '最大登录错误次数不能为空', trigger: 'blur' },
    { min: 1, max: 2, message: '输入长度不能超过2位，必须大于0', trigger: 'blur' },
    { validator: validateMaxErrorSize, required: true, trigger: 'blur' }
  ],
  lockTime: [
    { required: true, message: '登录失败，账户锁定时间（秒）不能为空', trigger: 'blur' },
    { min: 1, max: 5, message: '', trigger: 'blur' }
  ],
  accessTokenValiditySeconds: [
    { required: true, message: '会话保持时间（秒）不能为空', trigger: 'blur' },
    { min: 1, max: 5, message: '', trigger: 'blur' }
  ],
  minLength: [
    { required: true, message: '密码最小长度不能为空', trigger: 'blur' },
    { min: 1, max: 2, message: '', trigger: 'blur' }
  ],
  // passwordComplexity: [{ required: true, message: '密码复杂度不能为空', trigger: 'blur' }],
  defaultPassword: [{ validator: validatePassword, required: true, trigger: 'blur' }],
  maxFileSize: [
    { required: true, message: '最大上传文件（M）不能为空', trigger: 'blur' },
    { min: 1, max: 5, message: '', trigger: 'blur' }
  ],
  isSaveSample: [{ required: true, message: '是否保存样本文件不能为空', trigger: 'blur' }],
  isOpenAssetAudit: [{ required: true, message: '是否开启资产录入审核不能为空', trigger: 'blur' }],
  isOpenAssetAuditSensitive: [
    { required: true, message: '是否开启资产敏感级别自动变更审核不能为空', trigger: 'blur' }
  ],
  auditExpiresDay: [{ required: true, message: '审核有效性（天）不能为空', trigger: 'blur' }],
  likeThreshold: [
    {
      required: true,
      trigger: 'blur',
      validator: (rule: any, value: any, callback: any) => {
        if (saveValue.value.likeThreshold) {
          callback()
        } else {
          callback(new Error('请输入相似度阈值'))
        }
      }
    }
  ],
  likeSignAlgo: [
    {
      required: true,
      trigger: 'change',
      validator: (rule: any, value: any, callback: any) => {
        if (saveValue.value.likeSignAlgo.length !== 0) {
          callback()
        } else {
          callback(new Error('请选择相似度指纹算法'))
        }
      }
    }
  ],
  rulePriority: [{ validator: validateRule, required: true, trigger: 'blur' }],
  filePriority: [{ validator: validateFile, required: true, trigger: 'blur' }],
  modulePriority: [{ validator: validatemodule, required: true, trigger: 'blur' }],
  isDataMark: [{ validator: validatePass, trigger: 'change', required: true }]
}

const fieldList = [
  {
    label: '数据保护标准'
  },
  {
    label: '分类'
  },
  {
    label: '分级'
  },
  {
    label: '保密期限'
  },
  {
    label: '定密日期'
  },
  {
    label: '解密日期'
  },
  {
    label: '解密后等级'
  },
  {
    label: '归属机构'
  },
  {
    label: '归属系统'
  }
]

const timeUnit = [
  {
    label: '年'
  },
  {
    label: '月'
  },
  {
    label: '日'
  }
]

const passwordComChange = () => {
  console.log('formData.value.passwordComplexity', formData.value.passwordComplexity)
}

const isOpenAssetAuditChange = async () => {
  try {
    if (!formData.value.isOpenAssetAudit) {
      const content = '关闭后，所有正在流转的任务将做拒绝处理！'
      await message.confirm(content)
    }
  } catch {
    // 取消后,恢复
    formData.value.isOpenAssetAudit = true
  }
}
const isOpenAssetAuditSensitiveChange = async () => {
  try {
    if (!formData.value.isOpenAssetAuditSensitive) {
      const content = '关闭后，资产敏感级别到期自动变更将直接生效无需审核！'
      await message.confirm(content)
    }
  } catch {
    // 取消后,恢复
    formData.value.isOpenAssetAuditSensitive = true
  }
}

const submit = () => {
  formRef.value.validate(async (valid) => {
    if (valid) {
      const data = cloneDeep(formData.value)

      data.passwordComplexity = formData.value.passwordComplexity.join(',')
      // TODO:验证默认密码规则
      data.fileHiddenConfig = JSON.stringify(formData.value.fileHiddenConfig)
      data.classificationPattern = JSON.stringify(saveValue.value)
      delete data.refreshTokenValiditySeconds
      data.priority1 = '1'
      data.priority2 = '2'
      data.priority3 = '3'
      data.priority4 = '4'
      const res = await ConfigApi.clientUpdate(data)
      if (res) {
        ElMessage.success('操作成功')
      }
    }
  })
}

const SetConfig = (type) => {
  proxy?.$Drawer({
    params: {
      type,
      objJson: formData.value[`config${type}`],
      callBack: (e) => {
        console.log('e', e)
        if (type == 'One') {
          formData.value.configOne = JSON.stringify(e)
        } else if (type == 'Two') {
          formData.value.configTwo = JSON.stringify(e)
        } else if (type == 'Three') {
          formData.value.configThree = JSON.stringify(e)
        }
      }
    },
    title: `级别变更提醒配置`,
    size: '70%',
    component: import('./components/configSet.vue')
  })
}

const getConfig = async () => {
  const data = await ConfigApi.clientGet()
  formData.value = data
  formData.value.passwordComplexity = data.passwordComplexity.split(',')
  formData.value.logExpiresDay = data.logExpiresDay + ''
  formData.value.maxErrorSize = data.maxErrorSize + ''
  formData.value.lockTime = data.lockTime + ''
  formData.value.accessTokenValiditySeconds = data.accessTokenValiditySeconds + ''
  formData.value.refreshTokenValiditySeconds = data.refreshTokenValiditySeconds + ''
  formData.value.minLength = data.minLength + ''
  formData.value.defaultPassword = data.defaultPassword + ''
  formData.value.maxFileSize = data.maxFileSize + ''
  formData.value.auditExpiresDay = data.auditExpiresDay + ''

  formData.value.fileHiddenConfig = data.fileHiddenConfig ? JSON.parse(data.fileHiddenConfig) : null
  saveValue.value = data.classificationPattern
    ? JSON.parse(data.classificationPattern)
    : saveValueCopy
  console.log(saveValue.value)
}
onMounted(() => {
  getConfig()
})
</script>

<style lang="scss" scoped></style>
